package com.starblink.store.memanage.adapter

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.starblink.android.basic.adapter.BaseVH
import com.starblink.android.basic.ext.click
import com.starblink.android.basic.ext.dp2px
import com.starblink.android.basic.sensorsdata.extension.businessSuffixId
import com.starblink.android.basic.sensorsdata.extension.trackData
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmElementDef
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmPageDef
import com.starblink.rocketreserver.fragment.MerchantWebVOF

class SubStoresHolder(
    parent: ViewGroup,
//    val list: List<MerchantWebVOF>,
    val pageTrackTag: String = "",//
    val listener: (Int, MerchantWebVOF) -> Unit,
    val isLastOne: () -> Unit,
) : BaseVH<MerchantWebVOF>(ItemStoreMeManageView(parent.context)) {

    private val cardView = itemView as ItemStoreMeManageView

    init {
        val lp: RecyclerView.LayoutParams = RecyclerView.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            dp2px(74f)
        )
        itemView.layoutParams = lp
    }

    override fun onBind(merchat: MerchantWebVOF, position: Int) {
        cardView.bindPost(merchat)
        itemView.click {
            listener.invoke(position, merchat)
        }
        itemView.trackData(
            page = SpmPageDef.MeStoresSubListPage,
            element = SpmElementDef.ELE_33032,
            params = mapOf("merchantName" to "${merchat.merchantName}"),
//            businessSuffixID = businessSuffixId("My_MerchantWebVOF", merchat.id)
            businessSuffixID = businessSuffixId(merchat)
        )

//        if (list.size > 10 && position == list.size - 6) {
//            isLastOne()
//        }
    }

}